package day_2022_9_to_12.Day;

import java.util.Arrays;

/**
 * @author haomin
 * @date 2022/09/21 16:15
 **/
public class Day19_2_Num621_LeastInterval {
    class Solution {
        public int leastInterval(char[] tasks, int n) {
            int[] data = new int[26];
            for(char c : tasks){
                data[c-'A']++;
            }
            Arrays.sort(data);
            int minLen = (n + 1) * (data[25] - 1) + 1;
            for(int i = 24; i >= 0; --i){
                if(data[i] == data[25]) minLen++;
            }
            return Math.max(minLen, tasks.length);
        }
    }
}